package me.zhengjie.tools.domain

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import jakarta.persistence.*
import me.zhengjie.modules.system.service.dto.JobDTO
import org.apache.commons.lang3.builder.ToStringBuilder
import org.hibernate.annotations.CreationTimestamp
import org.springframework.data.redis.core.RedisHash
import java.sql.Timestamp

/**
 * @author Kuki Wu
 * @date 2019-09-05
 */
@Entity
@Table(name = "tool_local_storage")
@JsonTypeName("LocalStorage")
@RedisHash("localstorage")
data class LocalStorage(// 真实文件名
    @Column(name = "real_name") var realName: String? =null, // 文件名
    @Column(name = "name" ) var name: String? =null, // 后缀
    @Column(name = "suffix") var suffix: String?=null, // 路径
    @Column(name = "path") val path: String?=null, // 类型
    @Column(name = "type") var type: String?=null, // 大小
    @Column(name = "size") var size: String?=null, // 操作人
    @Column(name = "operate") var operate: String?=null,

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    val id: Long? = null,

    @Column(name = "create_time")
    @CreationTimestamp
    var createTime: Timestamp? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): LocalStorage? {
            val obj=JacksonUtil.parseObject(json, LocalStorage::class.java)!!
            return when(obj){
                is LocalStorage -> obj
                else -> null
            }
        }
    }
    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: LocalStorage?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}